<template>
  <div>
    <a-modal :title="title" :visible="visible" :confirm-loading="loading" ok-text="提交" :width="1000" @ok="save" @cancel="cancel">
      <div class="about-master-container">
        <a-form-model ref="form" :model="queryParam" :rules="rules" :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }" :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
          <a-row :gutter="24">
            <a-col :md="12" :sm="12">
              <a-form-model-item label="科目名称" prop="name">
                <BaseInput v-model="queryParam.name" placeholder="请输入" />
              </a-form-model-item>
            </a-col>
            <a-col :md="12" :sm="12">
              <a-form-model-item label="是否自动生成对应的劳务费、专业分包、机械费、材料费" prop="isGenerate">
                <a-select v-model="queryParam.isGenerate">
                  <a-select-option :value="1">生成</a-select-option>
                  <a-select-option :value="0">不生成</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </div>
      <div slot="footer" class="btn_box">
        <a-button type="default" @click="cancel"> 取消 </a-button>
        <a-button :disabled="btnDisabled" type="primary" @click="save"> 确定 </a-button>
      </div>
    </a-modal>
  </div>
</template>
  
  <script>
import { insertSelective } from '@/api/businessAffairs/accountManagement.js'

export default {
  name: 'a' + Date.now(),
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    selectRow: {
      type: Object
    }
  },
  data() {
    return {
      loading: false,
      queryParam: {},
      title: '新增二级科目', //标题
      btnDisabled:false,
      rules: {
        name: [{ required: true, message: '请填写', trigger: 'blur' }],
        isGenerate: [{ required: true, message: '请选择', trigger: 'blur' }]
      }
    }
  },
  watch: {
    visible(e) {
      if (e) {
        this.queryParam = this.form || { isGenerate: 1 }
      } else {
        this.queryParam = {}
      }
    }
  },
  methods: {
    async save() {
      this.$refs.form.validate(async (valid) => {
        if (valid) {
          this.loading = true
          try {
            let params = this.$clone(this.queryParam)
            params.parentId = this.selectRow.id
            if (this.selectRow.id) {
              this.btnDisabled = true;
              insertSelective(params).then((res) => {
                 this.btnDisabled = false;
                if (res.code == '0') {
                  this.loading = false
                  this.$noticeSuccess('保存成功')
                  this.$emit('ok', params)
                  this.cancel()
                }
              })
            }
          } catch (e) {
            this.loading = false
            this.btnDisabled = false;
          }
        }
      })
    },
    cancel() {
      this.$emit('update:visible', false)
    }
  }
}
</script>
  
  <style lang="less" scoped>
@deep: ~'>>>';
.about-master-container {
  .ant-row {
    .ant-col {
      &:last-child {
        @{deep} .ant-form-item-label {
          width: 220px;
        }
        @{deep} .ant-form-item-control-wrapper {
          width: calc(100% - 220px);
        }
      }
    }
  }
}
</style>
  